<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('名称')">
              <a-input :placeholder="$t('请输入名称')" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'BisAppletBannerController:add'">{{$t('新增')}}</a-button>
      <a-button @click="handleSet" type="primary" v-has="'BisAppletBannerController:edit'">{{$t('轮播间隔')}}</a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('无图片')}}</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">{{$t('无文件')}}</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'BisAppletBannerController:edit'">{{$t('编辑')}}</a>

          <a-divider type="vertical" v-has="'BisAppletBannerController:edit'"/>
          <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
            <a v-has="'BisAppletBannerController:delete'">{{$t('删除')}}</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <bis-applet-banner-modal ref="modalForm" @ok="modalFormOk"></bis-applet-banner-modal>
    <banner-set-modal ref="setModal"></banner-set-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BisAppletBannerModal from './modules/BisAppletBannerModal'
  import BannerSetModal from './modules/BannerSetModal'

  export default {
    name: 'BisAppletBannerList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      BisAppletBannerModal,
      BannerSetModal
    },
    data () {
      return {
        description: '小程序banner图设置管理页面',
        // 表头
        columns: [
          {
            title:this.$t('排序'),
            align:"center",
            sorter: true,
            dataIndex: 'sort'
          },
          {
            title:this.$t('名称'),
            align:"center",
            dataIndex: 'name'
          },
          {
            title:this.$t('开始时间'),
            align:"center",
            dataIndex: 'beginTime'
          },
          {
            title:this.$t('结束时间'),
            align:"center",
            dataIndex: 'endTime'
          },
          {
            title:this.$t('跳转页面'),
            align:"center",
            dataIndex: 'jumpType_dictText'
          },
          {
            title:this.$t('缩略图'),
            align:"center",
            dataIndex: 'picture',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title: this.$t('操作'),
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/applet/bisAppletBanner/list",
          delete: "/applet/bisAppletBanner/delete",
          deleteBatch: "/applet/bisAppletBanner/deleteBatch",
          exportXlsUrl: "/applet/bisAppletBanner/exportXls",
          importExcelUrl: "applet/bisAppletBanner/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        queryParam:{
          type:0,
        }
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'sort',text:this.$t('排序'),dictCode:''})
        fieldList.push({type:'string',value:'name',text:this.$t('名称'),dictCode:''})
        fieldList.push({type:'datetime',value:'beginTime',text:this.$t('开始时间')})
        fieldList.push({type:'datetime',value:'endTime',text:this.$t('结束时间')})
        fieldList.push({type:'string',value:'picture',text:this.$t('缩略图'),dictCode:''})
        this.superFieldList = fieldList
      },
      searchReset(){
        this.queryParam = {
          type:0,
        }
        this.loadData(1)
      },
      handleSet(){
        this.$refs.setModal.show()
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>